package com.comment.project;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

/**
 * @author liupenghui
 * @date 2018/7/12
 * @desc：
 */
public class Stream {
    public static void main(String[] args) {
        Student stuA = new Student(1, "A", "M", 184);
        Student stuB = new Student(2, "B", "G", 163);
        Student stuC = new Student(3, "C", "M", 175);
        Student stuD = new Student(4, "D", "G", 158);
        Student stuE = new Student(5, "E", "M", 170);
        List<Student> list = new ArrayList<>();
        list.add(stuA);
        list.add(stuB);
        list.add(stuC);
        list.add(stuD);
        list.add(stuE);

        Iterator<Student> iterator = list.iterator();
        while (iterator.hasNext()) {
            Student student = iterator.next();
            if ("G".equals(student.getSex())) {
                System.out.println(student.no);
            }
        }

        list.stream().filter(student -> "G".equals(student.getSex())).forEach(student -> {
            System.out.println(student.getNo());
        });
        list.stream().forEach(student -> {
            System.out.println("==" + student.getHeight());
        });

        // 排序
        Collections.sort(list, (p1, p2) -> (int) (p2.getHeight() - p1.getHeight()));
//        Collections.sort(list, (p1, p2) ->{
//
//            return 0;
//        });

        list.stream().forEach(student -> {
            System.out.println("==" + student.getHeight());
        });


    }
}

class Student {
    int no;
    String name;
    String sex;
    float height;

    public Student(int no, String name, String sex, float height) {
        this.no = no;
        this.name = name;
        this.sex = sex;
        this.height = height;
    }

    public int getNo() {
        return no;
    }

    public void setNo(int no) {
        this.no = no;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public float getHeight() {
        return height;
    }

    public void setHeight(float height) {
        this.height = height;
    }
}

